package com.link510.nbiot.cmcc;

import com.link510.nbiot.cmcc.domain.commands.CacheCommandDTO;
import com.link510.nbiot.cmcc.domain.commands.CacheCommandOutDTO;
import com.link510.nbiot.cmcc.domain.device.FindIMEIDeviceOutDTO;
import com.link510.nbiot.cmcc.exption.OnenetNBException;
import com.link510.nbiot.cmcc.helper.UnixTimeHelper;
import com.link510.nbiot.cmcc.impl.AbstractNBIoTClientImpl;
import com.link510.nbiot.cmcc.invokeapi.CommandManagement;
import com.link510.nbiot.cmcc.invokeapi.DeviceManagement;

import java.util.Calendar;

public class demo2 {

    public static void main(String[] args) {


        String apiKey = "TqTmKgXUmuFh31GAZvoWqsk8IiA=";

        AbstractNBIoTClientImpl ioTClient = new AbstractNBIoTClientImpl() {

            @Override
            public String getApiKey() {
                return apiKey;
            }

            @Override
            public String getApiSecret() {
                return "";
            }
        };

        DeviceManagement deviceManagement = new DeviceManagement(ioTClient);

        try {

            FindIMEIDeviceOutDTO d2 = deviceManagement.findImei("869029035197069");


            System.out.println(d2.toString());
        } catch (OnenetNBException ex) {
            System.out.println(ex.getError());
            ex.printStackTrace();
        }

        CommandManagement commandManagement = new CommandManagement(ioTClient);

        try {

            Integer expiredTime = UnixTimeHelper.getAfterTime(Calendar.DAY_OF_MONTH, 1);


            CacheCommandDTO commandDTO = CacheCommandDTO.builder().imei("869029035197069").expiredTime(expiredTime).args("ping").build();

            System.out.println(commandDTO.toString());

            CacheCommandOutDTO commandOutDTO = commandManagement.sendCacheCommand(commandDTO);
            if (commandOutDTO != null) {
                System.out.println("发送成功");
            }

        } catch (OnenetNBException ex) {
            System.out.println(ex.getError());
            ex.printStackTrace();
        }


    }
}
